﻿/// <reference path="Core.ts" />

module Supernova {
    
    export class Cheats {

        private static previousHash: string = '';

        public static detect() {
            if (window.location.hash != Cheats.previousHash) {
                if (galaxy !== null) {
                    if (window.location.hash == '#god' || window.location.hash == '#rich') Cheats.moneyAndScience();
                    if (window.location.hash == '#god' || window.location.hash == '#unlock') Cheats.unlockAll();
                    if (window.location.hash == '#discover') Cheats.discoverAll();
                    if (window.location.hash == '#jump') Cheats.jumpToLevel(parseInt(prompt('Enter level number', '20')));
                    if (window.location.hash == '#performance') Cheats.performanceTest();
                } else {
                    if (window.location.hash == '#serverCommand') channel.invoke.serverCommand(prompt('Enter server command:', ''));
                }
                Cheats.previousHash = window.location.hash;
                window.location.hash = '';
            }
        }

        private static moneyAndScience() {
            galaxy.gold = 100000;
            galaxy.science = 100000;
        }

        private static unlockAll() {
            while (galaxy.effects.available.length > 0) {
                var effect = galaxy.effects.available[0];
                if (effect.category != EffectCategory.trait) {
                    galaxy.effects.activate(effect);
                } else {
                    var index = galaxy.effects.available.indexOf(effect);
                    galaxy.effects.available.splice(index, 1);
                }
            }
        }

        private static discoverAll() {
            galaxy.discoverAll();
        }

        private static jumpToLevel(level: number) {
            while (galaxy.ai.level < level) {
                galaxy.ai.advanceToNextLevel();
            }
            galaxy.ai.timeToNextSpawn = 0;
        }

        private static performanceTest() {
            //#warning Need a new implementation
        }

    }

}